package com.cn.jx.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <p>WebConfiguration 系统启动拦截
 * 
 * @author <h1>jiangxu2  2019年11月21日</h1>
 * @version v1.11.20.2019
 * @since 1.0
 * 
 * @see #addInterceptors(InterceptorRegistry)
 * @see #addResourceHandlers(ResourceHandlerRegistry)
 * 
 */
@Configuration
@ComponentScan
@EnableWebMvc
@EnableScheduling
public class WebConfiguration   implements WebMvcConfigurer {
	
	/**
	 * 定义{@link LoginInterceptor loginInterceptor <tt>定义登录拦截器</tt>}
	 */
	@Autowired  
	LoginInterceptor loginInterceptor;
	
	/**
	 * 定义{@link CommonInterceptor commonInterceptor <tt>定义通用拦截器</tt>}
	 */
	@Autowired  
	CommonInterceptor commonInterceptor;
	
	/**
	 * 定义{@link DataBaseInterecptor dataBaseInterecptor <tt>定义数据拦截器</tt>}
	 */
	@Autowired
	DataBaseInterecptor dataBaseInterecptor;
	
	
	/**
	 * 添加拦截器
	 */
	@Override
    public void addInterceptors(InterceptorRegistry registry) {
		/**首页拦截 拦截产品过期*/
		registry.addInterceptor(dataBaseInterecptor).addPathPatterns("/admin/index");//首页拦截
		/**通用拦截获取系统配置*/
        registry.addInterceptor(commonInterceptor)
        .addPathPatterns("/admin/index")
        .addPathPatterns("/login/page")
        .addPathPatterns("/init/page/**")
        .addPathPatterns("/document/**");
        /**登录拦截 防止未登录操作 */
        registry.addInterceptor(loginInterceptor)
        .addPathPatterns("/admin/**");//登录拦截
    }

	/**
	 * 添加资源路径
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		WebMvcConfigurer.super.addResourceHandlers(registry);
	}

}
